package com.spring_shiro.sys_shiro;

import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class ShiroConfig {


    //创建工厂
    @Bean
    public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultWebSecurityManager securityManager){
        ShiroFilterFactoryBean bean=new ShiroFilterFactoryBean();
        //设置安全管理器
        bean.setSecurityManager(securityManager);
        Map<String,String> map=new HashMap<>();
        map.put("/user/shiroGetTest","authc");
        map.put("/pic/**","anon");

        bean.setFilterChainDefinitionMap(map);

        bean.setLoginUrl("/toLogin");
        return bean;


    }
    @Bean("securityManager")
    public DefaultWebSecurityManager getDefaultWebSecurityManager(UserRealm userRealm){
        DefaultWebSecurityManager securityManager=new DefaultWebSecurityManager();
        securityManager.setRealm(userRealm);
        return securityManager;
    }

    /*1、创建自定义对戏那个*/
    @Bean("userRealm")
    public UserRealm  getUserRealm(){
        UserRealm userRealm = new UserRealm();
        return userRealm;
    }

}
